//
//  BSSocketHandler.h
//  BSProject
//
//  Created by nsm on 2019/8/8.
//  Copyright © 2019 beisheng. All rights reserved.
//

#import <Foundation/Foundation.h>

NS_ASSUME_NONNULL_BEGIN

#pragma pack(1)

// 发送数据头
struct BSHeaderSend {
    unsigned char   seq;    //!< 命令序号
    unsigned char   cmd;    //!< 命令码
    unsigned short  len;    //!< 数据长度
};

// 收到数据头
struct BSHeaderRecv {
    unsigned char   cmd;    //!< 命令码
    unsigned short  len;    //!< 数据长度
};

struct BSVersion {
    struct BSHeaderRecv header;         //!< 头部数据

    unsigned char   sysVer[8];          //!< Main系统
    unsigned char   seqVer[8];          //!< Table程序
    unsigned char   initVer[8];         //!< 初始化数据
    unsigned char   motVer[8];          //!< Motion系统
    unsigned char   spcVer[8];          //!< 轴参数
    unsigned char   svcVer[8][8];       //!< Axis Servo
    unsigned short  blockNo;            //!< BlockNo
    unsigned char   blockComment[20];   //!< BlockComment
};

struct BSMachineInfo {
    struct BSHeaderRecv header;     //!< 头部数据
    
    unsigned char MachineNo[16];
    unsigned char IP[4];
    unsigned char SubMask[4];
    unsigned char Default_Getway[4];
    unsigned char DNS[4];
};

struct BSWInfo {
    struct BSHeaderSend header;     //!< 头部数据
    
    unsigned char value;
};

struct BSDataSendO {
    struct BSHeaderSend header;     //!< 头部数据
    
    unsigned char   flg;            //!< 操作按键标志
    unsigned char   operate;        //!< 操作数据
    unsigned char   manualSpeed;    //!< 手动速度
    unsigned char   autoSpeed;      //!< 自动速度
    unsigned char   freeSpeed;      //!< 自由操作速度
    unsigned short  keyCode;        //!< Key Code
    unsigned short  cursorCode;     //!< Cursor Code
    unsigned char   dpCode;         //!< DP Code
    unsigned short  no;             //!< 段换取No
};

struct BSDataRecvO {
    struct BSHeaderRecv header;     //!< 头部数据
    
    unsigned short  smo;            //!< 取出状态机SMO
    unsigned short  done;           //!< 成型周期
    unsigned short  take;           //!< 取出周期
    unsigned short  all;            //!< 全周期
    unsigned int    num;            //!< 取出数
    unsigned char   operateCode;    //!< 操作错误No.
    unsigned char   tipCode;        //!< 提示信息No.
    unsigned char   manualSpeed;    //!< 手动速度
    unsigned char   autoSpeed;      //!< 自动速度
    unsigned char   moveWarning;    //!< 动作警报
    unsigned char   sysWarning;     //!< 系统警报
    unsigned char   warning[8];     //!< 轴伺服警报
    unsigned short  blockNo;        //!< BlockNo
    unsigned char   blockComment[20];   //!< BlockComment
};

CF_EXTERN_C_BEGIN

int       DataToInt(NSData *data, int idx, int len);
NSString *DataToString(const void *data);

CF_EXTERN_C_END


@interface BSSocketHandler : NSObject
@end

NS_ASSUME_NONNULL_END
